package com.etu.jsonservices.dto;

import com.etu.jsonservices.util.StringUtils;

/**
 * Bean representing the basic response to be returned to the client
 * application. All responses must have the name of the original service
 * requested.
 * 
 * @author uye
 * 
 */
public abstract class BaseJSONResponse implements IJSONResponse {

	/**
	 * The default http response code of "OK".
	 */
	private static final String SUCCESS_STATUS_CODE = "200";

	/**
	 * Original service call.
	 */
	private String callbackName;

	/**
	 * Always provide the name of the callback so the client will know why its
	 * getting a response. Normally set to the name of the original request
	 * 
	 * @param callbackName
	 *            The name of the callback on the client
	 */
	public BaseJSONResponse(final String callbackName) {
		this.setCallbackName(callbackName);
	}

	/**
	 * Get this response's code.
	 * 
	 * @return HTTP OK response code
	 */
	public String getStatusCode() {
		return SUCCESS_STATUS_CODE;
	}

	/**
	 * Convert the response into its JSONString representation.
	 * @return JSON representation
	 */
	public String toString() {
		return StringUtils.toJSONString(this);
	}

	/**
	 * The name of the function to execute once the client receives this
	 * response.
	 * 
	 * @return The callback's name
	 */
	public String getCallbackName() {
		return callbackName;
	}

	/**
	 * Set the name of the client's function to call. Normally set to the name
	 * of the original service call.
	 * 
	 * @param callbackName Name of the function to call
	 */
	public void setCallbackName(final String callbackName) {
		this.callbackName = callbackName;
	}
}
